package com.example.demo.controller;

import com.example.demo.message.StreamMessage;
import com.example.demo.procss.MqProcess;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.google.gson.Gson;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.integration.message.AdviceMessage;
import org.springframework.integration.support.MessageBuilder;
import org.springframework.messaging.Message;
import org.springframework.messaging.support.GenericMessage;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.time.LocalDateTime;

/**
 * @Description
 * @Author liumin0901@sunwayworld.com
 * @Date 2021/4/27 19:14
 */
@RestController
@RequestMapping("/rocketmq")
public class RocketMQController {

    @Autowired
    private MqProcess mqProcess;

    @PostMapping("/sendmq")
    public void sendmq(@RequestBody StreamMessage streamMessage){
        streamMessage.setCreateDate(LocalDateTime.now());
        Gson gson = new Gson();
        String rst=gson.toJson(streamMessage);
        GenericMessage<String> genericMessage = new GenericMessage<>(rst);

        try {
            mqProcess.mq_output1().send(genericMessage,10);

        } catch (Exception e) {
            e.printStackTrace();
        }

    }
}
